package com.bjqg.bjqg01.bjqg.adapter;

import android.content.Context;
import android.database.Cursor;
import android.widget.SimpleCursorAdapter;

import com.bjqg.bjqg01.bjqg.bean.SeekBean;
import com.bjqg.greendao.SeekDao;
import com.bjqg.greendao.SeekHelper;

/**
 * Created by bjqg01 on 2018/8/23.
 */

public class AutoCompleteAdater extends SimpleCursorAdapter {
    private final int source;
    private static SeekHelper myUC = null;
    // 查询字段
    private String queryField;

    // 查询字段
    @SuppressWarnings("deprecation")
    public AutoCompleteAdater(Context context, int layout, Cursor c, String from, int to, int source) {
        super(context, layout, c, new String[]{from}, new int[]{to});
        this.source = source;
        this.queryField = from;
    }

    /**
     * 动态查询数据库
     */
    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        if (constraint != null) {
            return myUC.query((String) constraint);
        } else {
            return null;
        }
    }

    /**
     * 这里设置在弹出的提示列表中点击某一项后的返回值,返回值将被显示在文本框中
     */
    @Override
    public CharSequence convertToString(Cursor cursor) {
        return cursor.getString(1);
    }
}
